package com.plr.booker;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class AC2UTest {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) {

//		String url = "https://tst-ws-ac2u.aircanada.com/20110328/DirectConnect/LowFareSearch/MultiCityLFSWS";
		
		String url = "https://ws-ac2u.aircanada.com/20110328/DirectConnect/LowFareSearch/DCLowFareSearchWS";

	
		
		URL myURL;
		try {
			myURL = new URL(url);

			HttpURLConnection connection = (HttpURLConnection) myURL.openConnection();
			connection.setDoOutput(true);
			connection.setInstanceFollowRedirects(false);
			connection.setRequestMethod("POST"); 
		    connection.setRequestProperty("Content-Type", "text/xml"); 
		    connection.setRequestProperty("charset", "utf-8");

		    
		    OutputStream os = connection.getOutputStream();

		    TransformerFactory tf = TransformerFactory.newInstance();
		    Transformer transformer = tf.newTransformer();
		    FileReader fileReader = new FileReader("LFS3.xml");
		    StreamSource source = new StreamSource(fileReader);
		    StreamResult result = new StreamResult(os);
		    transformer.transform(source, result);

		    
		    os.flush();
		 
		  
		    
		    
		    System.err.println(connection.getResponseCode());
			InputStream is = connection.getInputStream();
			
			
			

			try (BufferedReader in = new BufferedReader(new InputStreamReader(
					is))) {
				String inputLine;
				while ((inputLine = in.readLine()) != null) {
					System.out.println(inputLine);
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
